var getMajorTreeListByProject = function(){
	var data_list;
	var project_id = $.trim($("#project_id").val());
	$.ajax({
	    url: base + "/projectCenter/treeapi/getProjectDesignByPid/"+project_id,
	    async: false,
	    success: function (data, textStatus, jqXHR) {
	    	data_list = data;
	    },
	    error: function () {
	    }
	});
	return data_list;
}

var initData = function(data){
	var html = "";
	if(data != null && data.length > 0){
		$.each(data,function(index,value){
			var design_type = data[index];
			var children_data = design_type.children;
			html += '<li>';
			if(children_data != null && children_data.length > 0){
				html += '<a class="inactive active li-off" node_type = "'+design_type.node_type+'" data_url = "'+base+design_type.xurl+'">'+design_type.name;
			}else{
				html += '<a class="li-on" node_type = "'+design_type.node_type+'" data_url="'+base+design_type.xurl+'">'+design_type.name;
			}
		    if(children_data != null && children_data.length > 0){
			   html += ' <ul style="display: none">';
			   for(var j=0;j<children_data.length;j++){
				   html += ' <li class="last"><a node_type = "'+children_data[j].node_type+'" data_url="'+base+children_data[j].xurl+'">'+children_data[j].name+'</a></li>'
			   }
			   html += ' </ul>';
		    }
		    html += ' </a></li>';
		});
	}
	return html;
}

$("body").delegate(".active","click",function(){
    if($(this).siblings('ul').css('display')=='none'){
        $(this).addClass('inactives').removeClass("inactive");
        $(this).siblings('ul').slideDown(100).children('li');
    }else{
    	$(this).addClass('inactive').removeClass("inactives");
        $(this).siblings('ul').slideUp(100);
    }
});

$("body").delegate("#left-menu a","click",function(){
	$("#left-menu a").removeClass('actived');
	$(this).addClass('actived');
});

$("#left-menu").delegate("a","click",function(){
	var url = $(this).attr("data_url");
	var project_id = $.trim($("#project_id").val());
	var design_name = $.trim($(this).text());
	var node_type = $(this).attr("node_type");
	if("设计评审" == design_name){
		url = base+"/projectCenter/sjps/index/"+project_id;
	}else if("设备选型" == design_name){
		url = base+"/projectCenter/businessdata/equipmentDesign/"+project_id;
	}else if("单体图设计" == design_name){
		url = base+"/projectCenter/businessdata/singleDrawDesign/"+project_id;
	}else if("总图设计" == design_name){
		url = base+"/projectCenter/businessdata/totalDrawDesign/"+project_id;
	}else if ("提出资料"==design_name){
		url = base+"/projectCenter/tczl/index/"+project_id;
	}else if ("协同设计"==design_name){
        url = base+"/projectCenter/coordinateDesign/index/"+project_id;
    }else if ("辅助机车交路设计软件"==design_name){
        url = base+"/projectCenter/bimAdapter/index/"+project_id;
    }else if("动车设施"==design_name){
    	url = base+"/projectCenter/treeapi/trainfacilities/"+project_id;
    }else if("动车/机务设施" == design_name){
    	url = base+"/projectCenter/treeapi/maintenanceFacilities/"+project_id;
    }
	
    $.get(url, function(result){
	   $("#mention_data").html("");
	   $("#mention_data").html(result);
    });
});

var go_back_project_list = function(){
	location.href = base+"/projectCenter/projects";
}

//设备配备
var getEquipmentEquipHtml = function(){
	$("iframe").attr("src",base+"/projectCenter/businessdata/equipmentEquip/"+project_id);
}

//打开设计常量取用页面
var getConstantHtml = function(){
    $("iframe").attr("src",base+"/projectCenter/designcell/index/"+mention_id+"/"+project_id);
}

//打开设计单元页面
var getDesignCellHtml = function(){
    $("iframe").attr("src",base+"/projectCenter/designcell/dcsj/"+mention_id+"/"+project_id);
}

var getSjpsHtml = function(){
    $("iframe").attr("src",base+"/projectCenter/sjps/index/"+project_id);
}


$(document).ready(function(){
var data = getMajorTreeListByProject();
var html_content = initData(data);
$("#left-menu").html(html_content);
$("#left-menu").find("li").find("ul").find(".inactive").remove();
});



